#include "window.hpp"
#include "sdltool.hpp"

namespace sdl_engine {

Window::Window(const Window::CreateInfo& createInfo) {
    window_ = SDL_CreateWindow(createInfo.title_.c_str(),
                               createInfo.position_.x, createInfo.position_.y,
                               createInfo.size_.w, createInfo.size_.h,
                               createInfo.flags_);
    if (!window_) {
        LogeWithSDLErr("Window create failed");
    } else {
        if (!createInfo.iconFilename_.empty()) {
            SDL_SetWindowIcon(window_,
                              IMG_Load(createInfo.iconFilename_.c_str()));
        }
        if (createInfo.opacity_) {
            SDL_SetWindowOpacity(window_, createInfo.opacity_.value());
        }
    }
}

Window::~Window() {
    SDL_DestroyWindow(window_);
    Logt("window deconstructor called");
}

void Window::ToggleFullScreen() {
    if (IsFullScreen()) {
        SDL_SetWindowFullscreen(window_, 0);
    } else {
        SDL_SetWindowFullscreen(window_, SDL_WINDOW_FULLSCREEN);
    }
}

void Window::Minimize() {
    SDL_MinimizeWindow(window_);
}

void Window::Maximize() {
    SDL_MaximizeWindow(window_);
}

void Window::Hide() {
    SDL_HideWindow(window_);
}

void Window::Show() {
    SDL_ShowWindow(window_);
}

Size Window::GetSize() const {
    Size size;
    SDL_GetWindowSize(window_, &size.w, &size.h);
    return size;
}

}
